<?php

    //support single login to manage different sub domain
    $request = new CHttpRequest();
    $domain = parse_url($request->getHostInfo(), PHP_URL_HOST);



$envFile = dirname(__FILE__).'/../../sites/env/config.'.str_replace('.admin.','.',$domain).'.php';
if (!file_exists($envFile)) 
    include 'offline.php';
else
    include $envFile;
    
// uncomment the following to define a path alias
Yii::setPathOfAlias('site',dirname(__FILE__).'/../../sites/'.SITE_DIR.'/protected');
Yii::setPathOfAlias('runtime', Yii::getPathOfAlias('site').DIRECTORY_SEPARATOR.'runtime');
Yii::setPathOfAlias('sites',dirname(__FILE__).'/../../sites');

$modules = array(
        'Core' => array (
            //Sub modules
            'modules' => array(
                'auth'
            ),
        ),
        'gii'=>array(
            'class'=>'system.gii.GiiModule',
            'generatorPaths'=>array('Core.extensions.gii.generators'),
            'password'=>'123456',
        ),
        'Admin' => array(),
        'User' => array(),
        'Cms' => array(),
        'SiteManagement' => array(),
);

$modules = array_merge($modules, include(Yii::getPathOfAlias('runtime').'/modules.php'));

// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'runtimePath'=>Yii::getPathOfAlias('site').DIRECTORY_SEPARATOR.'runtime',
    'name'=>'',

    // modules
    'modules'=>$modules,

    // preloading 'log' component
    'preload'=>array('log','core','urlManager','cmsManager','sessionCache'),

    // autoloading model and component classes
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'Core.components.*',
        'Admin.components.helpers.*',
        'Admin.models.*',
        'User.models.*',
    ),
    
    'defaultController'=>'site',

    // application components
    'components'=>array(
        'core'=>array(
            'class' => 'Core.extensions.FlexiCore',
            'FrontendRenderer' => false,
        ),
        'user'=>array(
            'allowAutoLogin'=>true,
            'autoRenewCookie'=>true,
            'identityCookie'=>array(
                'domain'=>strstr($domain,'.'),
            )
        ),
        'cmsManager'=>array(
            'class'=>'Cms.components.CmsManager',
        ),
        'localeManager'=>array(
            'class'=>'Core.extensions.i18n.LocaleManager',
        ),
        'session'=>array(
            'cookieParams'=>array(
                'domain'=>$domain,
            )
        ),
        'authManager' => array(
            'class' => 'FAuthManager',
            'assignmentTable'=>SITE_TABLE_PREFIX.'authassignment',
            'itemTable'=>SITE_TABLE_PREFIX.'authitem',
            'itemChildTable'=>SITE_TABLE_PREFIX.'authitemchild',
        ),
        'db'=>array(
            'connectionString' => $dbs['default']['connectionString'],
            'username' => $dbs['default']['username'],
            'password' => $dbs['default']['password'],
            'enableParamLogging'=>true,
            // cache
            'schemaCachingDuration'=> 0, //60*30, // 30 minutes
            'queryCachingDuration'=>0,
        ),
        'errorHandler'=>array(
            'class' => 'Core.extensions.base.FErrorHandler',
            //use 'site/error' action to display errors
            'sendNotificationEmail'=>true,
            'sendNotificationTo'=>'',
            'excludedCodes'=>array(404),
        ),
        'urlManager'=>array(
            'class'=>'Cms.extensions.CmsUrlManager',
            'urlFormat'=>'path',
            'showScriptName'=>false,
            'rules'=>array(
            ),
        ),
        'assetManager' => array(
            'basePath'=>Yii::getPathOfAlias('site').DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'assets',
            'baseUrl'=>str_replace(DIRECTORY_SEPARATOR,'/','/sites/'.SITE_DIR.'/assets'),
        ),
        'themeManager'=>array(
            'basePath'=>Yii::getPathOfAlias('site').'/../themes'
        ),
        'config'=>array(
                'class'=>'Core.extensions.CConfiguration',
        ),
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                    'levels'=>'error, warning, info',
                ),
                // uncomment the following to show log messages on web pages
                //
//                array(
//                    'class'=>'CWebLogRoute',
//                ),
                //
            ),
        ),
        'messages' => array(
            'class' => 'CDbMessageSource',
            'sourceMessageTable' => SITE_TABLE_PREFIX.'sourcemessage',
            'translatedMessageTable' => SITE_TABLE_PREFIX.'translatedmessage',
        ),
        //Config mailer go here :
        /*'mail' => array(
            'class' => 'application.modules.Core.extensions.vendors.mail.YiiMail',
            'transportType' => 'smtp',
            'transportOptions' => array(
                'host'=>'smtp.gmail.com',
                'username'=>'mailer@webflexica.com',
                'password'=>'m41l3r',
                'port'=>465,
                'encryption'=>'ssl',
            ),
            'logging' => true,
            'dryRun' => false
        ),  */
        'widgetFactory'=>array(
            'enableSkin'=>true,
        ),
       /* 'cache'=>array(
            'class'=>'system.caching.CDbCache',
            'connectionID'=>'db',
            'autoCreateCacheTable'=>true,
            'cacheTableName'=>'yii_cache',
        ),*/
        'socials'=>array(
            'class'=>'Cms.extensions.socials.CSocialConnecter',
            'providers'=>array(
                'twitter'=>array(//use OAuth 1.0
                    'class'=>'Cms.extensions.socials.TwitterProvider',
                    'server'=>array(
                        'consumer_key' => 'IAP889ZwpTXM34Foa3Xzww',
                        'consumer_secret' => '3y2iLB2szO2RcjhVwf3ErlkjlfgNYzZp2XGbDVD82E',
                        'server_uri' => 'https://api.twitter.com',
                        'signature_methods' => array('HMAC-SHA1', 'PLAINTEXT'),
                        'request_token_uri' => 'https://api.twitter.com/oauth/request_token',
                        'authorize_uri' => 'https://api.twitter.com/oauth/authorize',
                        'access_token_uri' => 'https://api.twitter.com/oauth/access_token',
                    ),
                ),
                'facebook'=>array(//use OAuth 2.0
                    'class'=>'Cms.extensions.socials.FacebookProvider',
                    'server'=>array(
                        'appId' => '117819041650076',
                        'secret' => '2e0b6d1bb00f86e56b903ab2f4277ae6',
                    ),
                    'useProxy'=>false,
                ),
            ),
        ),
    ),

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    // 'params'=>require(dirname(__FILE__).'/params.php'),
);